<?php
if (get_template_type() == 'header') {
    ?>
    <style>
        body {
        <?php $item = tpl_get("基本设置");?> background: <?php echo $item[0]['color']?> !important;
        }
    </style>
    <link rel="stylesheet" href="/shop/templates/mln/list.css">

    <section class="top">
        <div class="wrapper">
            <style>
                .top_link span {
                    position: relative;
                    display: inline-block;
                    line-height: 36px;
                    cursor: pointer;

                }

                .top_link span:hover {
                    background: #fff;
                }

                .top_link span:hover #recent_view {
                    display: block;
                }

                .top_link span #recent_view {
                    position: absolute;
                    display: none;
                    top: 36px;
                    left: 0;
                    background: #fff;
                    width: 348px;
                    box-sizing: border-box;
                    padding-left: 10px;
                    padding-right: 10px;
                    padding-bottom: 8px;
                    padding-top: 10px;
                    z-index: 100;
                }

                .top_link span table {
                    width: 100%;
                }

                .top_link .cart {
                    background: #f60;
                    line-height: 32px;
                    margin-left: 60px;
                    padding-right: 20px;
                    padding-left: 20px;
                    display: inline-block;
                    color: #fff;
                    text-decoration: none;
                }

                .top_link .cart:hover {
                    text-decoration: none;
                }

                .top_link .cart b {
                    display: inline-block;
                    width: 15px;
                    height: 15px;
                    border-radius: 15px;
                    border: 1px solid #fff;
                    /* font-size: 10px; */
                    line-height: 16px;
                    font-size: 12px;
                    text-align: center;
                    vertical-align: 0px;
                }

                .top_link table tr {
                    height: 80px;
                    border-bottom: 1px solid #ddd;
                    padding-left: 10px;
                    padding-right: 10px;
                }

                .top_link ._remove {
                    text-decoration: none;
                }

                .top_link ._remove {
                    text-decoration: none;
                }
            </style>
            <div class="link top_link">
                <a href="/shop/index.php?act=member_favorites&op=fglist" style="padding-left: 0;">收藏夹</a>
                <code>|</code>
                <span href="javascript:;">最近浏览
                    <div id="recent_view">
                        <table>
                            <?php
                            $recent = cookie('recent_goods') or $recent = '[]';
                            $recent = json_decode($recent, true);
                            $goods = Model()->table('goods')->where(array('goods_id' => array('in', $recent)))->select();
                            foreach ($goods as $k => $g) {
                                ?>
                                <tr
                                    <?php
                                    if ($k == count($goods) - 1) {
                                        echo 'style="border-bottom : 0"';
                                    }
                                    ?>
                                >
                                    <td>
                                        <img src="<?php echo thumb($g, 50, 1) ?>" style="width: 50px;height: 50px;">
                                    </td>
                                    <td>
                                        <p style="line-height: 18px;font-size: 13px;color: #f60;"><?php echo $g['goods_name'] ?></p>

                                        <p style="line-height: 18px;font-size: 13px;"><?php echo $g['goods_jingle'] ?>
                                            &nbsp;</p>
                                    </td>
                                    <td>
                                        <small style="line-height: 18px;display: inline-block;vertical-align: top;">
                                            <?php echo $g['goods_price'] ?>
                                            元

                                        </small>
                                    </td>
                                    <td>
                                        <a data-id=<?php echo $g['goods_id'] ?> href="javascript:;" class="_remove"
                                           style="line-height: 18px;display: inline-block;vertical-align: top;">
                                            x
                                        </a>
                                    </td>
                                </tr>

                                <?php
                            }
                            ?>
                        </table>
                        <div>
                            <a href="/shop/?act=cart" class='cart'>
                                <b class="icon icon-plus">
                                </b>
                                购物袋
                            </a>
                            <a href="javascript:;" class="remove_all" style="color: #666;font-size: 12px;float: right;">全部删除</a>
                        </div>
                    </div>
                </span>
                <script>
                    $('.top_link .remove_all').click(function () {
                        $.get('/shop/?act=seccode&op=remove_recent', function () {
                            $('.top_link tr').fadeOut();
                        })
                    });

                    $('.top_link ._remove').click(function () {
                        var id = $(this).attr('data-id');
                        var _this = $(this);
                        $.get('/shop/?act=seccode&op=remove_recent', {id: id}, function () {
                            _this.closest('tr').fadeOut();
                        });
                    })


                </script>
                <code>|</code>
                <a href="javascript:;" class="_wait">联系客服</a>
                <code>|</code>
                <a href="javascript:;" class="_wait">投诉建议</a>
                <code>|</code>
                <a href="/shop/index.php?act=article&op=article&ac_id=35">帮助中心</a>

            </div>
            <script>
                $('.top_link a').click(function () {
                    if ($(this).hasClass('_wait')) {
                        layer.msg("等待集成客服插件");
                    }
                })
            </script>

            <div class="menu">
                <div class="language">
                    <a href="" class="lm">
                        中文
                        <span class="icon icon-angle-down"></span>
                    </a>

                    <div class="others">
                        <a href="">法文</a>
                        <a href="">俄文</a>
                        <a href="">火星语</a>
                    </div>
                </div>
                <?php
                if (isset($_SESSION['member_id'])) {
                    ?>
                    <style>
                        .menu .language, .menu .member_center {
                            margin-right: 15px !important;
                        }
                    </style>
                    <div class="member_center">
                        <a href="javascript:;" class="lm">
                            <?php
                            echo $_SESSION['member_name'];
                            ?>
                            <span class="icon icon-angle-down"></span>
                        </a>

                        <div class="others">
                            <a href="/shop/index.php?act=member_order">我的订单</a>
                            <a href="javascript:;" id="logout">退出登录</a>
                        </div>
                        <script>
                            $('#logout').click(function () {
                                $.get('/shop/?act=login&op=logout', function (msg) {
                                    location.reload();

                                }, 'json');
                            });
                        </script>
                    </div>
                    <?php
                } else {
                    ?>
                    <a href="/shop/?act=login">登录</a>
                    |
                    <a href="/shop/?act=login&op=register">注册</a>
                    <?php
                }
                ?>

            </div>
        </div>
    </section>

    <section class="logon">
        <div class="wrapper">
            <div class="logon">
                <?php
                $img = tpl_get("logo");

                ?>
                <a href="<?php echo $img['link'] ?>">
                    <img src="<?php echo $img['pic'] ?>" alt="" style="width: 160px;height: 124px;float: left;">
                </a>
            </div>
            <section class="search">
                <input type="text" class='keyword' placeholder="法国红酒、瑞士名表">
                <span class="icon icon-search" style="cursor: pointer;"></span>
            </section>
            <script>
                $('.keyword').keyup(function (e) {
                    if (e.keyCode == 13) {
                        $('section.search span.icon-search').trigger('click');
                    }
                });

                $('section.search span.icon-search').click(function () {
                    if ($.trim($('.keyword').val()) == '') {
                        layer.msg("请输入要搜索的内容");
                        return;
                    }
                    var url = "/shop/?act=search&keyword=" + $('.keyword').val();
                    location.href = url;
                })
            </script>
        </div>

    </section>

    <style>
        #_nav {
        <?php
            $base = tpl_get("基本设置");

        ?> background: url(<?php echo $base[1]['nav']['pic']?>) repeat-x !important;
            background-size: contain;
        }
    </style>
    <nav id="_nav">
        <script>
            function update_cart_num() {
                $.get("/shop/?act=seccode&op=update_cart_num", function (msg) {
                    if (msg == '') {
                        msg = 0;
                    }
                    $('#cart_count').html(msg);
                })
            }
        </script>
        <div class="wrapper" style="position: relative;height: 100%;">
            <a href="/shop/?act=cart"
               style="background: url(/shop/templates/mln/images/package.png) no-repeat;display: block;width: 37px;height: 48px;position: absolute;right: -19px;top: -13px;text-align: center;">
                <span style="
                    width: 15px;
                    height: 15px;
                    border-radius: 15px;
                    margin-top: 23px;
                    margin-left: 13px;
                    background: red;
                    display: block;
                    line-height: 15px;
                    font-size: 12px;
    " id="cart_count">
                    <?php

                    ?>

                    <?php echo Model('cart')->countCartByMemberId($_SESSION['member_id']); ?>
                </span>
            </a>
            <?php
            $nav = get_nav();
            foreach ($nav as $link) {

                if (is_array($link)) {
                    foreach ($link as $l) {
                        echo "<a href='$l[nav_url]'>$l[nav_title]</a>";
                    }
                } else {
                    echo "<a href='/'>$link</a>";
                }
            }
            ?>
        </div>

    </nav>
    <?php
}
?>

<?php
if (get_template_type() == 'index') {
    ?>


    <link rel="stylesheet" href="/shop/templates/haidao/js/unslider/css/unslider.css">
    <link rel="stylesheet" href="/shop/templates/haidao/js/unslider/css/unslider-dots.css">
    <style>
        .unslider {
            position: relative;
        }

        .unslider-nav {
            position: absolute;
            bottom: 0px;
            display: block;
            width: 100%;
            background: none !important;
            text-align: right;
        }

        .unslider-nav ol {
            text-align: right;
            padding-right: 50px;
        }

        .unslider-nav ol li {
            background: #ddd;
            border-color: #ddd;
            width: 10px;
            height: 10px;
            border-radius: 10px;
            border: 3px solid #ddd;
            text-indent: 999em;
        }

        .unslider-nav ol li.unslider-active {
            background: #000;
        }

        .s_goods {
            width: 300px;
            height: 247px;
            float: left;
            display: block;
            border-right: 1px solid #ddd;
            border-bottom: 1px solid #ddd;
            text-decoration: none;
            position: relative;
            z-index: 10;
        }

        .s_goods:hover {
            text-decoration: none;
            box-shadow: 0 0 4px 4px rgba(0, 0, 0, .25);
            z-index: 100;
        }

        .s_goods:hover .name {
            color: #f60 !important;
        }
    </style>
    <script src="/shop/templates/haidao/js/jquery.js"></script>
    <script src="/shop/templates/haidao/js/unslider/js/unslider-min.js"></script> <!-- but with the right path! -->
    <script>$(function () {
            $('.automatic-slider').unslider({autoplay: true, arrows: false, dots: true})
        })</script>

    <section class="middle">
        <div class="wrapper">
            <div class="left">
                <ul>
                    <?php
                    $all_cats = Model('goods_class')->getGoodsClassListByParentId(0);
                    foreach ($all_cats as $item) {
                        ?>
                        <li>
                            <img src="/data/upload/shop/common/category-pic-<?php echo $item['gc_id'] ?>.jpg" alt="">
                            <?php
                            echo $item['gc_name'];
                            ?>
                            <dl>
                                <dt>
                                    <?php
                                    echo $item['gc_name'];
                                    ?>
                                </dt>
                                <?php
                                $cat2 = Model('goods_class')->getGoodsClassListByParentId($item['gc_id']);
                                foreach ($cat2 as $i) {
                                    ?>
                                    <dd>
                                        <a href="/shop/?act=search&cate_id=<?php echo $i['gc_id'] ?>"
                                           class="nm"><?php echo $i['gc_name'] ?>：</a>

                                        <div class="_child">

                                            <?php
                                            $cat3 = Model('goods_class')->getGoodsClassListByParentId($i['gc_id']);
                                            foreach ($cat3 as $_cat) {
                                                ?>
                                                <a href="/shop/?act=search&cate_id=<?php echo $_cat['gc_id'] ?>"><?php echo $_cat['gc_name'] ?></a>
                                                <?php
                                            }
                                            ?>
                                        </div>

                                    </dd>
                                    <?php
                                }
                                ?>
                                <dd>
                                </dd>
                            </dl>
                        </li>
                        <?php
                    }
                    ?>
                </ul>
            </div>
            <div class="right automatic-slider" style="width: 1023px;">
                <ul>
                    <?php
                    $imgs = tpl_get("首页轮播");
                    foreach ($imgs as $img) {
                        ?>
                        <li>
                            <a href="<?php echo $img['link'] ?>" target="_blank">
                                <img src="<?php echo $img['pic'] ?>" alt="" style="width: 1023px;height: 461px;">
                            </a>
                        </li>
                        <?php
                    }
                    ?>
                </ul>
            </div>
        </div>

    </section>

    <section class="ads">
        <div class="wrapper">
            <?php
            $imgs = tpl_get(("中部广告位"));
            ?>
            <a href="<?php echo $imgs[0]['link'] ?>">
                <img src="<?php echo $imgs[0]['pic'] ?>" alt="">
            </a>
            <a href="<?php echo $imgs[1]['link'] ?>">
                <img src="<?php echo $imgs[1]['pic'] ?>" alt="">
            </a>
            <a href="<?php echo $imgs[2]['link'] ?>" style="margin-right: 0;">
                <img src="<?php echo $imgs[2]['pic'] ?>" alt="">
            </a>
        </div>
    </section>

    <section class="floor">
        <div class="wrapper">
            <?php
            $floors = tpl_get("楼层");
            foreach ($floors as $floor) {
                switch ($floor['style']) {
                    case '1':
                        $h = '415px';
                        break;

                    case '2':
                        $h = '505px';
                        break;

                    case '3':
                        $h = '560px';
                        break;

                    default:
                        $h = 'auto';


                }
                ?>
                <div class="f" style="height:<?php echo $h; ?>">
                    <div class="head">
                        <div class="lt"></div>
                        <div class="rt"></div>
                        <div class="lb"></div>
                        <div class="rb"></div>
                        <?php
                        echo $floor['floor_name'];
                        ?>
                        <?php
                        if (!empty($floor['all_link'])) {
                            ?>
                            <a href="<?php echo $floor['all_link'] ?>" style="">查看全部>></a>
                            <?php
                        }
                        ?>
                    </div>
                    <div class="short_link">
                        <?php
                        $arr = explode(',', $floor['short_link']);
                        foreach ($arr as $key => $item) {
                            ?>
                            <a href="/shop/?act=search&keyword=<?php echo $item; ?>"><?php echo $item; ?></a>
                            <?php
                            if (count($arr) - 1 > $key) {
                                echo '<span>/</span>';
                            }
                            ?>
                            <?php
                        }
                        ?>
                    </div>
                    <div class="body">
                        <?php
                        if ($floor['style'] == 1) {
                            $arr = array('g1', 'g2', 'g3', 'g4');
                            $condition = array();
                            foreach ($arr as $item) {
                                if (!empty($item)) {
                                    $condition[] = $floor[$item];
                                }
                            }
                            $gmlist = Model()->table('goods_common')->where(array('goods_commonid' => array('in', $condition)))->select();

                            foreach ($gmlist as $gminfo) {
                                $ginfo = Model()->table('goods')->where(array('goods_commonid' => $gminfo['goods_commonid']))->find();


                                ?>
                                <div class="item">
                                    <div style="height: 25px;"></div>
                                    <a href="<?php echo urlShop('goods', 'index', array('goods_id' => $ginfo['goods_id'])); ?>"
                                       class="img">
                                        <img src="<?php echo thumb($ginfo, 240, 1) ?>" alt="">
                                    </a>

                                    <div class="name">
                                        <p>
                                            <b><?php echo $ginfo['goods_name'] ?></b>
                                        </p>

                                        <p>
                            <span>
                            <?php
                            echo $ginfo['goods_jingle'];
                            ?>
                            </span>
                                        </p>

                                    </div>
                                    <div class="price">
                                        ￥
                                        <?php
                                        echo $ginfo['goods_price'];
                                        ?>
                                    </div>
                                </div>
                                <?php
                            }
                        } else if ($floor['style'] == 2) {
                            ?>
                            <div>
                                <a style="float: left;" href="<?php echo $floor['img1']['link'] ?>">
                                    <img style="width: 600px;height: 230px;" src="<?php echo $floor['img1']['pic'] ?>"
                                         alt="">
                                </a>
                                <a style="float: left;" href="<?php echo $floor['img2']['link'] ?>">
                                    <img style="width: 600px;height: 230px;" src="<?php echo $floor['img2']['pic'] ?>"
                                         alt="">
                                </a>
                            </div>
                            <div>
                                <a style="float: left;" href="<?php echo $floor['img3']['link'] ?>">
                                    <img style="width: 400px;height: 230px;" src="<?php echo $floor['img3']['pic'] ?>"
                                         alt="">
                                </a>
                                <a style="float: left;" href="<?php echo $floor['img4']['link'] ?>">
                                    <img style="width: 400px;height: 230px;" src="<?php echo $floor['img4']['pic'] ?>"
                                         alt="">
                                </a>
                                <a style="float: left;" href="<?php echo $floor['img5']['link'] ?>">
                                    <img style="width: 400px;height: 230px;" src="<?php echo $floor['img5']['pic'] ?>"
                                         alt="">
                                </a>
                            </div>

                            <?php
                        } else if ($floor['style'] == 3) {
                            ?>
                            <div style="float: left;background: #fff;">
                                <a href="<?php echo $floor['img']['link'] ?>">
                                    <img src="" alt="" style="width: 300px;height: 495px;">
                                </a>
                            </div>
                            <div style="float: left;width: 900px;height: 495px;background: #fff;">
                                <?php
                                $arr = array('g1', 'g2', 'g3', 'g4', 'g5', 'g6');
                                $condition = array();
                                foreach ($arr as $k => $item) {
                                    if (empty($floor[$item])) {
                                        continue;
                                    }

                                    $gminfo = Model('goods_common')->find($floor[$item]);
                                    $ginfo = Model()->table('goods')->where(array('goods_commonid' => $gminfo['goods_commonid']))->find();
                                    ?>
                                    <a href="/shop/?act=goods&goods_id=<?php echo $ginfo['goods_id']; ?>"
                                       class="s_goods" style="<?php
                                    if (in_array($k, array(0, 1, 3, 4))) {
                                        echo 'width:299px;';
                                    } else {
                                        echo 'border-right : 0;';
                                    }
                                    if (in_array($k, array(3, 4, 5))) {
                                        echo 'border-bottom : 0';
                                    }

                                    ?>">
                                        <img src="<?php echo thumb($ginfo, 200, 1) ?>"
                                             style="width: 200px;height: 200px;display: block;margin: 0 auto;">

                                        <div class="name"
                                             style="display: block;height: 48px;line-height: 48px;color: #686667;font-size: 15px;overflow: hidden;text-align: center;">
                                            <?php echo $ginfo['goods_name'] ?>
                                        </div>
                                    </a>
                                    <?php
                                }

                                ?>
                            </div>
                            <?php
                        } else if ($floor['style'] == 4) {
                            foreach ($floor['goods'] as $k => $gid) {
                                if (empty($gid)) {
                                    continue;
                                }
                                $gminfo = Model('goods_common')->find($gid);
                                $ginfo = Model()->table('goods')->where(array('goods_commonid' => $gminfo['goods_commonid']))->find();
                                if (!$ginfo) {
                                    continue;
                                }
                                ?>
                                <div class="item"
                                     style="display: inline-block;float: none;margin-right: 10px;margin-bottom: 10px;;width: 289px;<?php
                                     if ($k % 4 == 3) {
                                         echo 'margin-right:0;';
                                     }
                                     ?>">
                                <div style="height: 25px;"></div>
                                <a href="/shop/index.php?act=goods&goods_id=<?php echo $ginfo['goods_id'] ?>"
                                   class="img">
                                    <img src="<?php echo thumb($ginfo, 240); ?>"
                                         alt="">
                                </a>

                                <div class="name">
                                    <p>
                                        <b><?php echo $ginfo['goods_name'] ?></b>
                                    </p>

                                    <p>
                            <span>
                                <?php echo $ginfo['goods_jingle'] ?>
                                                        </span>
                                    </p>

                                </div>
                                <div class="price">
                                    ￥
                                    <?php echo $ginfo['goods_price']?>
                                </div>
                                </div><?php
                            }
                            ?>
                            <?php
                        }

                        ?>
                    </div>
                </div>

                <?php
            }
            ?>


            <!--            <div class="f">-->
            <!--                <div class="head">-->
            <!--                    <div class="lt"></div>-->
            <!--                    <div class="rt"></div>-->
            <!--                    <div class="lb"></div>-->
            <!--                    <div class="rb"></div>-->
            <!--                    酒品推荐-->
            <!--                </div>-->
            <!--            </div>-->
            <!--            <div class="f">-->
            <!--                <div class="head">-->
            <!--                    <div class="lt"></div>-->
            <!--                    <div class="rt"></div>-->
            <!--                    <div class="lb"></div>-->
            <!--                    <div class="rb"></div>-->
            <!--                    好评产品-->
            <!--                </div>-->
            <!--            </div>-->
        </div>
    </section>


    <?php
}
?>

<?php
if (get_template_type() == 'footer') {
    ?>
    <style>
        #faq {
            border-top: 18px solid #000 !important;
            color: #000;
        }

        #faq dt {
            color: #000 !important;
            border-bottom: 0 !important;
        }

        #faq dd a {
            color: #000 !important;
        }

        #faq ul li dt span {
            display: none;
        }

        #footer {
            border-top: 1px solid #fff !important;;
            padding-top: 15px;
        }

        #footer {
            color: #000 !important;
        }

        #footer a {
            color: #000 !important;
        }
    </style>
    <?php
}
?>
